<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Devices</title>
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='control_style.css') }}"/>
    <script src="{{ url_for('static', filename='jquery-1.10.2.js') }}"></script>
</head>
<body>
<div id="" class="left full-height">
    <!-- logo -->
    <div id="" class="logo-bar">
        <div id="" class="ele full-height">
            <h1 style="color: #ededed;">LOGO</h1>
        </div>

    </div>
    <!-- tabs -->
    <div id="" class="tab-bar">
        <div style="height: 50px;width: 100%"></div>
        <a href="/devices">
            <div id="" class="tab-content no-choix">
                DEVICES
            </div>
        </a>
        <a href="/types">
            <div id="" class="tab-content no-choix">
                TYPE
            </div>
        </a>
        <a href="/conn">
            <div id="" class="tab-content no-choix">
                CONNECTIONS
            </div>
        </a>
        <a href="/log">
            <div id="" class="tab-content no-choix">
                LOG
            </div>
        </a>
        <a href="/groups">
            <div id="" class="tab-content choix">
                GROUPS
            </div>
        </a>
    </div>
</div>

<div id="" class="right full-height">
    <!-- admin -->
    <div id="" class="admin-bar">

    </div>
    <!-- main content -->
    <div id="" class="content-background">
        <div class="content-box">
            <div id="" class="content-control-box">

                <button onclick="jump('/add_group')" class="btn">ADD</button>

            </div>
            <div id="" class="data-box" style="overflow-y: auto">
                <table id="table-groups" class="table_style" cellspacing=0>
                    <tr>
                        <th>group_id</th>
                        <th>group_name</th>
                        <th>device_names</th>
                        <th></th>
                    </tr>

                    {% for g in glist %}
                        <tr>
                            <td>{{ g[0] }}</td>
                            <td>{{ g[1] }}</td>
                            <td>{{ g[3] }}</td>
                            <td>
                                <button class="btn-small" onclick="jump('/modify_group/{{ g[0] }}')">
                                    modify
                                </button>
                                <button onclick="delete_groups({{ g[0] }})" class="btn-small">
                                    delete
                                </button>
                            </td>
                        </tr>
                    {% endfor %}
                </table>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    function jump(url) {
        window.location.href = url;
    }

    function create_xhr() {
        let XHR = [  //兼容不同浏览器和版本得创建函数数组
            function () {
                return new XMLHttpRequest()
            },
            function () {
                return new ActiveXObject("Msxml2.XMLHTTP")
            },
            function () {
                return new ActiveXObject("Msxml3.XMLHTTP")
            },
            function () {
                return new ActiveXObject("Microsoft.XMLHTTP")
            }
        ];
        let xhr = null;
        //尝试调用函数，如果成功则返回XMLHttpRequest对象，否则继续尝试
        for (let i = 0; i < XHR.length; i++) {
            try {
                xhr = XHR[i]();
            } catch (e) {
                continue  //如果发生异常，则继续下一个函数调用
            }
            break;  //如果成功，则中止循环
        }
        return xhr;  //返回对象实例
    }

    function delete_groups(group_id) {
        let delete_group_data = {}
        delete_group_data["group_id"] = group_id;
        $.ajax({
            type: "POST",
            url: "/equipmentGroup/deleteEquipmentGroup",
            'data': JSON.stringify(delete_group_data),
            'contentType': 'application/json',
            success: function (data) {
                console.log(data)
                location.reload();
            }
        });
    }

</script>
</html>